'use strict';
let fs=require('fs');
let fd=fs.openSync("./text.txt","w");
let info =fs.statSync("./text.txt");
let num=Math.round(Math.random()*10000);
for (var i=1;i<100000;i++){
    fs.writeSync(fd,num+"",{flag:'a'});
}
fs.closeSync(fd);
let fdread=fs.openSync("./text.txt","r");
fs.stat("./text.txt",function(err,stat){
    if(err){
        console.log(err);
    }else{
        console.log('isfile:'+stat.isFile());
        console.log('isdirectory:'+stat.isDirectory());
        if(stat.isFile()){
            console.log('size'+stat.size);
        }
    }
})
let bf = Buffer.alloc(500000);
fs.readSync(fdread, bf);
let obj = {};
let length = bf.toString().length;
for (var a = 1; a < length; a++) {
    var char = bf.toString().charAt(a);//返回指定索引处的字符
    if (obj[char]) {
        obj[char]++;
    } else {
        obj[char] = 1;
    }
}
//统计最大值
var max=0;
for (var key in obj) {
   if(max<obj[key]){
    max=obj[key];
   }
}
for (var key in obj) {
    if(obj[key]==max){
     console.log("出现最多次的字符是"+key+"出现次数为"+max+"次")
    }
 }